package com.boot.ys.mybatisplus.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.boot.ys.mybatisplus.entity.Role;
import com.boot.ys.mybatisplus.result.Result;
import com.boot.ys.mybatisplus.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author Code yang
 * @since 2021-10-21
 */
@RestController
@RequestMapping("/role")
@Api(tags = "角色表 测试")
public class RoleController {

    @Autowired
    RoleService roleService;

    @ApiOperation("获取全部数据")
    @GetMapping("/test")
    public List<Role> test(){
        List<Role> gettest = roleService.gettest();
        return gettest;
    }

    @ApiOperation("根据id查询数据")
    @GetMapping("/getById/{id}")
    public Role getById(@ApiParam(value = "Id",required = true)@PathVariable("id") String id){
        Role byId = roleService.getById(id);
        return byId;
    }


    @ApiOperation("分页查询数据")
    @GetMapping("/getPage")
    public Result getPage(){
        IPage page = roleService.getPage();
        return Result.ok(page);
    }


    @ApiOperation("实现条件查询")
    @PostMapping("/getWrapper")
    public Result getWrapper(@RequestBody Role role){
        List<Role> wrapper = roleService.getWrapper(role);
        return Result.ok(wrapper);
    }

    @ApiOperation("根据id实现更新")
    @PostMapping("/update")
    public Result update(@RequestBody Role role){
        roleService.update(role);
        return Result.ok();
    }

    @ApiOperation("根据id实现删除")
    @PostMapping("/deleteById")
    public Result deleteById(@RequestBody Role role){
        roleService.deleteById(role);
        return Result.ok();
    }

}
